

#ifndef __CE_RENDERCONTROLLER_H__
#define __CE_RENDERCONTROLLER_H__

#include <cegfx/ce.h>
#include <cegfx/ceexport.h>
#include <cegfx/cegeometrynode.h>
#include <cegfx/cerenderenv.h>
#include <cecore/iqf.h>
#include <map>

class ceCamera;
class ceClipper;
class ceEffect;
class ceClipper;
class ceMaterial;
class CE_GFX_API ceRenderController : public iBase
{
	IQF_DECLARATION;
private:
	ceGeometryNodeList nodes;
	std::map<ceEffect*, ceGeometryNodeList>	effectNodes;
	std::map<ceMaterial*, ceGeometryNodeList> materialNodes;

	ceGeometryNodeList transparentNodes;

	D3DXMATRIX matProj, matView, matWorld;

	D3DLIGHT9 light;

	RenderSort	sort;

	LPDIRECT3DDEVICE9 device;

	ceRenderEnv renderEnv;
private:
	void renderNodes (ceGeometryNodeList& nodes, unsigned pass, const ceClipper* clipper);
	void renderEffectNodes (unsigned pass, const ceClipper* clipper);
	void renderMaterialNodes (unsigned pass, const ceClipper* clipper);

	void applyGlobalEffectStates (ceEffect* effect);
	void applyEffectStates (ceEffect* effect, ceMaterial* material, ceTransform& transform, iGeometryAnimator* geometryAnimator);

public:
	ceRenderController ();
	~ceRenderController ();

	void SetDevice (LPDIRECT3DDEVICE9 device);
	LPDIRECT3DDEVICE9 GetDevice ();

	void Clear ();
	void DebugContent();

	void SetCamera (const ceCamera* camera);
	void SetProjectionMatrix (const D3DXMATRIX& matrix);
	void SetViewMatrix (const D3DXMATRIX& matrix);
	void SetWorldMatrix (const D3DXMATRIX& matrix);

	void SetLight (const D3DLIGHT9& light);
	const D3DLIGHT9& GetLight () const;

	void SetRenderSort (RenderSort sort);
	RenderSort GetRenderSort () const;

	void AddGeometryNode (ceGeometryNode* geometryNode, bool transparency = false);

	void Render (unsigned pass, const ceClipper* clipper);

};


#endif /* ! __CE_RENDERCONTROLLER_H__ */
